﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Maps;
using LiveCharts.WinForms;
using LiveCharts.Wpf;
using Brushes = System.Windows.Media.Brushes;

namespace CentralMonitoring
{
    public partial class MonitorFeFrm : Form
    {
        public MonitorFeFrm()
        {
            InitializeComponent();  
            initParasChart();
           
        }

        private void MonitorFeFrm_Load(object sender, EventArgs e)
        {
            #region 尺寸比例
            this.WindowState = FormWindowState.Maximized;
            this.panelLeft.Width = this.Width /5;
            this.panelRight.Width = this.Width /5;
            int CalHeight = this.Height - this.panelMenu.Height - this.panelReserve.Height;
            this.groupBoxLeftTop.Height = CalHeight / 3;
            this.groupBoxLeftMid.Height = CalHeight / 3;
            this.groupBoxRightTop.Height = CalHeight / 3;
            this.groupBoxRightMiddle.Height = CalHeight / 3;
            this.groupBoxDatas.Height = this.groupBoxleftButtom.Height;
            this.groupBoxFe.Height = this.groupBoxLeftMid.Height;
            #endregion          
            initAlarmChart();          
            initOiChart();
          

        } 
        #region 初始化图表  
        /// <summary>
        /// 预警图表初始化
        /// </summary>
        private void initAlarmChart()
        {
            #region 单曲线
            //carChartAlarm.Series.Clear();
            //List<string> lables = new List<string> { "温度", "粘度", "密度", "水分", "Fe", "NFe" };
            //Axis axis = new Axis
            //{
            //    Title = "名称",
            //    Labels = lables
            //};
            //ChartValues<double> vales = new ChartValues<double>();
            //for (int i = 0; i < lables.Count; i++)
            //{
            //    vales.Add(30 + i);
            //}
            //carChartAlarm.Series = new SeriesCollection
            //{
            //    new LineSeries
            //    {
            //        Title="运行数",
            //        Values=vales,
            //        Fill=new SolidColorBrush(Colors.Pink),
            //        Stroke=new SolidColorBrush(Colors.Azure),
            //        LineSmoothness=1

            //    }
            //};
            //carChartAlarm.AxisX.Add(axis);
            //carChartAlarm.AxisY.Add(new Axis
            //{
            //    Title = "数量",
            //    LabelFormatter = value => value.ToString()
            //});
            #endregion
            carChartAlarm.Series.Clear();
            List<string> titles = new List<string> { "粘度", "水分", "铁磁" };
            List<ChartValues<double>> _values = new List<ChartValues<double>> 
            { 
                new ChartValues<double> { 6, 5, 3 },
                new ChartValues<double> { 5, 8, 2},
                new ChartValues<double> { 3, 4, 1}
            };
            List<double> vis_datas = new List<double> { 6, 5, 3 };
            List<double> mo_datas = new List<double> { 3, 8, 2 };
            List<double> fe_datas = new List<double> {5,2,6 };
            List<string> _labels = new List<string>();
            SeriesCollection seriesViews = new SeriesCollection();
            for (int i = 0; i < titles.Count; i++)
            {
                LineSeries lineseries = new LineSeries();
                lineseries.DataLabels = true;
                lineseries.Title = titles[i];
                lineseries.Values = _values[i];
                lineseries.LineSmoothness = 1;
                lineseries.LabelPoint = (point => point.Y + "次");
                seriesViews.Add(lineseries);     
                _labels.Add(DateTime.Now.AddDays(i-3).ToString("yyyy-MM-dd"));
            }
            carChartAlarm.Series = seriesViews;
            Axis axis = new Axis
            {
                //Title = "名称",
                Labels = _labels

            };
            carChartAlarm.AxisX.Add(axis);
            carChartAlarm.AxisY.Add(new Axis
            {
                Title = "预警次数",
                LabelFormatter = value => value.ToString()
            });      
        }      
        /// <summary>
        /// 油品图表初始化
        /// </summary>
        private void initOiChart()
        {
            SeriesCollection seriesCollection = new SeriesCollection();
            LineSeries lineSeries = new LineSeries();
            List<string> labels = new List<string> { "320#", "220#", "150#","46#" };
            ChartValues<double> values = new ChartValues<double> { 5, 6, 10, 2 };
            lineSeries.Title = "油品";
            lineSeries.Values = values;
            lineSeries.DataLabels = true;
            Axis axis = new Axis();            
            axis.LabelFormatter = value => value.ToString();
            axis.Labels = labels;
            axis.Separator = new Separator() {IsEnabled=false };
            seriesCollection.Add(lineSeries);
            carChartOils.Series.Clear();
            carChartOils.Series.Add(lineSeries);
            carChartOils.AxisX.Add(axis);     
            Axis axis2 = new Axis();
            axis2.Title = "油品统计";
            axis2.Separator.IsEnabled = false;
            axis2.LabelFormatter = value => value.ToString() + "个";
            carChartOils.AxisY.Add(axis2);

        }
        /// <summary>
        /// 油品状态初始化
        /// </summary>
        private void initParasChart()
        {
            angularGauge1.Value = 65;
            angularGauge1.FromValue = 0;
            angularGauge1.ToValue = 100;
            angularGauge1.TicksForeground = Brushes.White;
            angularGauge1.Base.Foreground = Brushes.White;
            angularGauge1.Base.FontWeight = FontWeights.Bold;
            angularGauge1.Base.FontSize = 16;
            angularGauge1.SectionsInnerRadius = 0.5;
            angularGauge1.Sections.Add(new AngularSection
            {
                FromValue =0,
                ToValue =70,
                //Fill=new SolidColorBrush(System.Windows.Media.Color.FromRgb(247, 166, 37))
                Fill = new SolidColorBrush(Colors.Green)
            });
            angularGauge1.Sections.Add(new AngularSection
            {
                FromValue = 70,
                ToValue = 85,
                //Fill=new SolidColorBrush(System.Windows.Media.Color.FromRgb(247, 166, 37))
                Fill= new SolidColorBrush(Colors.Yellow)
            });
            this.Refresh();
            angularGauge1.Sections.Add(new AngularSection
            {
                FromValue = 85,
                ToValue = 100,
                //Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(247, 57, 57))
                Fill=new SolidColorBrush(Colors.Red)
            });
            angularGauge1.Refresh();

            //pieChartParas.Series.Clear();          
            //List<string> titles = new List<string> { "粘度", "水分","磨粒","清洁度"};
            //List<double> values = new List<double> { 10, 40, 30,20 };
            //SeriesCollection seriesCollection = new SeriesCollection();
            //Func<ChartPoint, string> labelPoint = chartPoint =>
            // string.Format("{0} ({1:P})", chartPoint.Y+"台", chartPoint.Participation);
            //for (int i = 0; i < titles.Count; i++)
            //{
            //    PieSeries series = new PieSeries();
            //    series.Title = titles[i];
            //    series.Values = new ChartValues<double> { values[i] };
            //    series.DataLabels = true;
            //    series.LabelPoint = labelPoint;
            //    seriesCollection.Add(series);
            //}
            //pieChartParas.Series = seriesCollection;
            //pieChartParas.LegendLocation = LegendLocation.Bottom;
        }       
        #endregion

        private void labelExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

        private void label26_Click(object sender, EventArgs e)
        {

        }
    }
}
